<script type="text/javascript" src="/IndexPublic/zchou/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        //调用微信JSapi 支付
        function jsApiCall(){
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',{$jsApiParameters},
                function(res){
                    writeObj(res);
                    return false;
                    //WeixinJSBridge.log(res.err_msg);
                    if(res.err_msg == 'get_brand_wcpay_request:ok') {
                    	alert("支付成功！");
						location.href=decodeURIComponent("{$orderinfo['geturl']}");
                    	
	                }else{
                        alert("支付失败！");
                        cdata({$orderinfo['lastinsertid']});
                        return;
	                }
                    
            	}
            );
        }
        function callpay(){
            if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                }else if (document.attachEvent){
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            }else{
                jsApiCall();
            }
        }
        callpay();

        function writeObj(obj){
            var description = "";
            for(var i in obj){
                var property=obj[i];
                description+=i+" = "+property+"\n";
            }
            alert(description);
        }

		function cdata(lastinsertid){
			$.post("{:U('Zchou/cdata')}", {lastinsertid:lastinsertid,random:Math.random()}, function(data){
				if(data==1){
					location.href=decodeURIComponent("{$orderinfo['geturl']}");
				}
			   
			})	
		}
    </script>